package com.company.cloud.oss.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

@Component
@ConfigurationProperties(prefix="oss.cloud.storage")
@Getter
@Setter
public class OssConfig {
	
	/**oss 分类*/
	private String ossType;

	/**AccessKeyId*/
	private String accessId;
	
	/**AccessKeySecret*/
	private String accessKey;
	
	/**endpoint*/
	private String endpoint;

	/**bucketname*/
	private String bucket;
	
	/**回调地址*/
	private String callbackUrl;
	
	/**用户上传文件时指定的前缀*/
	String dir = "";

	/**映射业务host*/
	private String bizHost;
	
	/***/
	public String getHost() {
		String host = "https://" + this.bucket + "." + this.endpoint;
		return host;
	}


	public String getShowHost(){
		if(StringUtils.isEmpty(this.bizHost)){
			return this.getHost();
		}else{
			return this.bizHost;
		}
	}


	public String getFileUrl(String fileName) {
		String host=this.getShowHost();
//		String host="https://img.artshanghaifair.com";
		return host+"/"+fileName;
	}


	
	
}
